<template>
  <div class="m-16px">
    <Form ref="form" :model="model" :rules="validationRules"  :mode="mode">
      <FormItem label="描述" required prop="name"  :single="true">
        <Input placeholder="请输入问题描述" v-model="model.name"/>
      </FormItem>
      <FormItem label="负责人" required prop="adminId">
        <Select :datas="adminList" keyName="id" titleName="name" placeholder="请选择负责人" v-model="model.adminId"/>
      </FormItem>
      <FormItem label="类型" required prop="TodoType">
        <Select :datas="todoType"  placeholder="需求类型" v-model="model.todoType"/>
      </FormItem>
      <FormItem label="关联项目" required  prop="projectId">
        <Select :datas="projectList" keyName="id" titleName="name"  placeholder="关联项目" v-model="model.projectId"/>
      </FormItem>
      <FormItem label="优先级" required prop="priority">
        <Select :datas="priority"  placeholder="优先级" v-model="model.priority"/>
      </FormItem>

    </Form>
    <div class="layui-layer-btn layui-layer-btn-r">
      <Button icon="fa fa-close" @click="$emit('close')" :loading="loading">
        取消
      </Button>
      <Button icon="fa fa-save" color="primary" @click="confirm" :loading="loading">
        保存
      </Button>
    </div>
  </div>
</template>

<script>
/**
 * @功能描述: 用户FORM
 * @创建时间: 2023年08月08日
 * @公司官网: www.fenxi365.com
 * @公司信息: 纷析云（杭州）科技有限公司
 * @公司介绍: 专注于财务相关软件开发, 企业会计自动化解决方案
 */
import TodoList from "@js/api/TodoList";
import {message} from "heyui";
import {CopyObj} from "@common/utils";
import Admin from "@js/api/Admin";
import Project from "@js/api/Project";
export default {
  name: "TodoListForm",
  props: {
    entity: Object,
  },
  data() {
    return {
      loading: false,
      projectList: [],
      adminList: [],
      todoType:{需求:'需求',任务:'任务',BUG:'BUG'},
      priority:{无优先级:'无优先级',严重:'严重',主要:'主要',次要:'次要',不重要:'不重要'},
      mode: 'twocolumn',
      model: {
        id: null,
        name: null,
        projectId:null,
        adminId:null,
        priority:'无优先级',
        todoType:'需求',
      },
      validationRules: {

      }
    }
  },
  methods: {
    confirm() {
      let validResult = this.$refs.form.valid();
      if (validResult.result) {
        this.loading = true;
        TodoList.save(this.model).then(() => {
          message("保存成功~");
          this.$emit('success');
        }).finally(() => this.loading = false);
      }
    },
  },
  created() {
    CopyObj(this.model, this.entity);
    console.log(this.model)
    Admin.list().then(({data}) => {
      this.adminList = data;
    })
    Project.list().then(({data}) => {
      this.projectList = data;
    })
  }
}
</script>
